package com.controller;

import com.pojo.UserCollection;
import com.service.UserCollectionService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "用户收藏API")
@Controller
public class UserCollectionController {
    @Autowired
    private UserCollectionService userCollectionService;
    @ApiOperation(value ="添加收藏",notes ="" )
    @PostMapping("/userCollection")
    @ResponseBody
    public ServerResponse add(UserCollection userCollection){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return userCollectionService.save(userCollection);
    }
    @ApiOperation(value = "根据收藏id删除收藏",notes ="")
    @DeleteMapping("/userCollection/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = userCollectionService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }
    /*
      修改用户信息
   */
    @ApiOperation(value ="修改收藏",notes ="" )
    @PutMapping("/userCollection")
    @ResponseBody
    public ServerResponse upd(UserCollection userCollection){
        System.out.println(userCollection);
        ServerResponse serverResponse = userCollectionService.modify(userCollection);
        return serverResponse;
    }
    /*
      根据id查询用户
   */
    @ApiOperation(value ="根据收藏id查询收藏信息")
    @GetMapping("/userCollection/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = userCollectionService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询收藏信息")
    @GetMapping("/userCollection/backhome")
    public String findAll(Model model){
        ServerResponse serverResponse = userCollectionService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/user/userCollection";
    }
}
